﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DATN.Common;
using DATN.Entities;

namespace DATN.DataAccess
{
    public class DiaDiemDataAccess
    {
        private SqlConnection conn;
        private SqlCommand cmd;
        public static DSDiadiem ParseToEntity(IDataRecord dataRecord)
        {
            return new DSDiadiem()
            {
                Ma = dataRecord["Ma"].ToStringOrDefault(),
                Ten = dataRecord["Ten"].ToStringOrDefault(),
                Ghi_chu = dataRecord["Ghi_chu"].ToStringOrDefault()
            };
        }
        public Collection<DSDiadiem> GetAllDiaDiem()
        {
            conn = new SqlConnection(AppConfig.ConnectionString);
            string truyvan = "Select * from DSDiadiem";
            cmd =new SqlCommand(truyvan,conn);
            conn.Open();

            using (IDataReader iDataReader = cmd.ExecuteReader())
            {
                Collection<DSDiadiem> collection = new Collection<DSDiadiem>();

                while (iDataReader.Read())
                {
                    collection.Add(ParseToEntity(iDataReader));
                }
                return collection;
            }
        }
    }
}
